package com.wenli.lt.controller;


import com.wenli.lt.entity.Collections;
import com.wenli.lt.service.ICollectionsService;
import com.wenli.lt.util.CommonResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lt
 * @since 2021-03-23
 */
@RestController
@Api(tags="收藏")
@RequestMapping("collections")
public class CollectionsController {

    @Autowired
    ICollectionsService iCollectionsService;

    /**
     * 新增收藏
     * @param collections
     * @return
     */
    @PostMapping("/addCollections")
    @ApiOperation("新增收藏")
    public CommonResponse addCollections(@RequestBody @ApiParam(name = "collections", value = "收藏") Collections collections){
        if (iCollectionsService.addCollections(collections)){
            return new CommonResponse("收藏成功");
        }else {
            return new CommonResponse(CommonResponse.ERROR_CODE,"收藏出错,请联系管理员!");
        }
    }

    /**
     * 取消收藏
     * @param goodsId 商品ID
     * @param collectionsStuNum  收藏者学号
     * @return
     */
    @PostMapping("deleteCollections")
    @ApiOperation("取消收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId",value = "商品ID",required = true),
            @ApiImplicitParam(name = "collectionsStuNum",value = "收藏者学号",required = true)
    })
    public CommonResponse deleteCollections(String goodsId,String collectionsStuNum){
        if (iCollectionsService.deleteCollections(goodsId,collectionsStuNum)){
            return new CommonResponse("收藏取消");
        }else {
            return new CommonResponse(CommonResponse.ERROR_CODE,"取消收藏出错,请联系管理员!");
        }
    }

    /**
     * 通过学号查询我的收藏
     * @param StudentNumber 学号
     * @return
     */
    @GetMapping("myCollections")
    @ApiOperation("我的收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "StudentNumber",value = "学生号")
    })
    public CommonResponse myCollections(String StudentNumber){
      List<Map> list =  iCollectionsService.myCollections(StudentNumber);
      return new CommonResponse(list);

    }




}
